package com.hspedu.Homework;
/*
 *@auther will
 *@version 1.0
 */


import java.util.ArrayList;
import java.util.List;

public class LIstExercise02 {
    public static void main(String[] args) {

        List list = new ArrayList();
        list.add(new Book("红楼梦","曹雪芹",100));
        list.add(new Book("西游记","吴承恩",10));
        list.add(new Book("水浒传","施耐庵",9));
        list.add(new Book("三国演义","罗贯中",80));
        list.add(new Book("西游记","吴承恩",10));
        for (Object o : list) {
            System.out.println(o);
        }

        int size = list.size();
        for (int i = 0; i < size-1; i++) {
            for (int j = 0; j < size - i-1; j++) {
                Book o = (Book) list.get(j);
               double jPrice=o.getPrice();
                Book o1 = (Book) list.get(j+1);
                double iPrice=o1.getPrice();
                Object temp=null;
                if (iPrice<jPrice){
                    temp=o;
                    list.set(j,o1);
                    list.set(j+1,temp);
                }
            }
        }
        System.out.println("===============");
        for (Object o : list) {
            System.out.println(o);
        }

    }
}


class Book{
    private String name;
    private String author;
    private double price;
    public Book(String name, String author, double price) {
        this.name = name;
        this.author = author;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "名称： " + name +
                "\t\t作者：" + author  +
                "\t\t价格：" + price;
    }
}